package com.ruoyi.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.IdVo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.UserLogVo;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.user.domain.TbRole;
import com.ruoyi.user.domain.TbUserLog;
import com.ruoyi.user.service.TbUserLogService;
import com.ruoyi.user.mapper.TbUserLogMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbUserLogServiceImpl extends ServiceImpl<TbUserLogMapper, TbUserLog>
    implements TbUserLogService{

    @Autowired
    private TbUserLogMapper tbUserLogMapper;

    @Override
    public R addUserLog(UserLogVo userLogVo) {

        TbUserLog tbUserLog = new TbUserLog();
        BeanUtils.copyProperties(userLogVo, tbUserLog);
        tbUserLog.setUpdateBy("admin");
        tbUserLog.setCreateBy("admin");
        int insert = tbUserLogMapper.insert(tbUserLog);

        return insert > 0 ? R.ok("添加成功") : R.fail("添加失败");
    }

    @Override
    public R deleteUserLogById(IdVo idVo) {
        int delete = tbUserLogMapper.deleteById(idVo.getId());

        return delete > 0 ? R.ok("删除成功") : R.fail("删除失败");
    }

    @Override
    public AjaxResult selectUserLogByUserId(IdVo idVo) {
        List<TbUserLog> tbUserLogs = tbUserLogMapper.selectList(null);

        return AjaxResult.success("查询可能为空",tbUserLogs);
    }

    @Override
    public R updateUserLog(UserLogVo userLogVo) {

        TbUserLog tbUserLog = new TbUserLog();
        BeanUtils.copyProperties(userLogVo, tbUserLog);
        tbUserLog.setUpdateBy("admin");
        tbUserLog.setUpdateTime(null);

        int update = tbUserLogMapper.updateById(tbUserLog);
        return update > 0 ? R.ok("修改成功") : R.fail("修改失败");
    }
}




